package com.powernobug.service.impl;

import com.powernobug.bean.vo.template.*;
import com.powernobug.bean.vo.data.*;
import com.powernobug.bean.vo.template.*;
import com.powernobug.service.*;
import com.powernobug.service.*;
import com.powernobug.bean.vo.data.GoodsListWithCategoryLevelData;
import com.powernobug.util.Constant;
import com.powernobug.util.SyncSubmitUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.Future;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-28
 * @Description:
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    MarketGoodsService marketGoodsService;
    @Autowired
    MarketCouponService marketCouponService;
    @Autowired
    MarketCategoryService marketCategoryService;
    @Autowired
    MarketAdService marketAdService;
    @Autowired
    MarketBrandService marketBrandService;
    @Autowired
    MarketTopicService marketTopicService;
    @Autowired
    SystemConfigService systemConfigService;

    @Override
    public Map<String, Object> getHomeIndexData() {
        // 从系统 ConfigMap 中获取数据量信息
        Integer newGoodsListLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_NEW);
        Integer brandListLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_BRAND);
        Integer hotGoodsListLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_HOT);
        Integer topicListLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_TOPIC);
        Integer catalogLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_CATLOG_LIST);
        Integer secondLevelGoodsLimit = (Integer) systemConfigService.getSystemConfigs().get(Constant.CONFIG_CATLOG_GOODS);

        Future<List<GoodsTempForHomeIndex>> task1 = marketGoodsService.getNewGoodsByLimit(newGoodsListLimit);
        Future<List<CouponsTempForHomeIndex>> task2 = marketCouponService.getCoupons();
        Future<List<CategoryTempForHomeIndex>> task3 = marketCategoryService.getChannels();
        Future<List<AdsTempForHomeIndex>> task4 = marketAdService.getBanners();
        Future<List<BrandsTempForHomeIndex>> task5 = marketBrandService.getBrandListByLimit(brandListLimit);
        Future<List<GoodsTempForHomeIndex>> task6 = marketGoodsService.getHotGoodsByLimit(hotGoodsListLimit);
        Future<List<TopicsTempForHomeIndex>> task7 = marketTopicService.getTopicListByLimit(topicListLimit);
        Future<List<GoodsListWithCategoryLevelData>> task8 = marketCategoryService.getFloorGoodsListByLimit(catalogLimit, secondLevelGoodsLimit);

        String[] keyArray = new String[] {
                "newGoodsList", "couponList", "channel", "banner",
                "brandList", "hotGoodsList", "topicList", "floorGoodsList"
        };
        List<Future> taskList = Arrays.asList(task1, task2, task3, task4, task5, task6, task7, task8);

        return SyncSubmitUtil.syncSubmitTaskToMap(keyArray,taskList);
    }
}
